n = int(input())
inp = list(map(int, input().split()))
s = True
cnt_25 = 0
cnt_50 = 0
for i in inp:
if i==25:
cnt_25 += 1
elif i==50 and cnt_25>0:
cnt_25-=1
cnt_50 += 1
elif i==100:
if (cnt_25 > 0 and cnt_50 > 0):
cnt_25 -= 1
cnt_50 -= 1
elif (cnt_25>2):
cnt_25 -= 3
else:
s = False
break
else:
s = False
break
print("YES" if s else "NO")
#include<bits/stdc++.h>
#define fastin cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0);
#define ll long long
#define int long long
#define endl '\n'
#define loop(i,start,n) for(int i=start;i<n;i++)
#define sz(a) a.size()
#define all(v) v.begin(), v.end()
using namespace std;
void solve()
{
int n,x,a25=0,a50=0,a100=0; cin >> n;
bool flag=1;
loop(i,0,n)
{
cin >> x;
if(x==25) a25++;
else
{
if(x==50)
{
if(a25==0)
{
flag=0;
continue;
}
else
{
a25--;
a50++;
}
}
else
{
if(a25<1)
{
flag=0;
continue;
}
else if(a50==0 && a25<3)
{
flag=0;
continue;
}
else
{
if(a50>0)
{
a50--;
a25--;
a100++;
}
else
{
a25-=3;
a100++;
}
}
}
}
}
flag? cout << "YES\n" : cout << "NO\n";
}
signed main()
{
fastin;
int tc = 1; //cin >> tc;
while (tc--)
solve();
}
468. Validate IP Address | 450. Delete Node in a BST |
445. Add Two Numbers II | 442. Find All Duplicates in an Array |
437. Path Sum III | 436. Find Right Interval |
435. Non-overlapping Intervals | 406. Queue Reconstruction by Height |
380. Insert Delete GetRandom O(1) | 332. Reconstruct Itinerary |
368. Largest Divisible Subset | 377. Combination Sum IV |
322. Coin Change | 307. Range Sum Query - Mutable |
287. Find the Duplicate Number | 279. Perfect Squares |
275. H-Index II | 274. H-Index |
260. Single Number III | 240. Search a 2D Matrix II |
238. Product of Array Except Self | 229. Majority Element II |
222. Count Complete Tree Nodes | 215. Kth Largest Element in an Array |
198. House Robber | 153. Find Minimum in Rotated Sorted Array |
150. Evaluate Reverse Polish Notation | 144. Binary Tree Preorder Traversal |
137. Single Number II | 130. Surrounded Regions |